'''


'''
from urllib import request
import sys
import re


class TestProxy:
    # 访问网址
    def checkProxy(proxyIp,type = 'HTTPS'):
        # 这是代理IP
        proxy = {
            type:proxyIp
        }
        # 创建ProxyHandler
        proxy_support = request.ProxyHandler(proxy)
        # 创建Opener
        opener = request.build_opener(proxy_support)
        # 添加User Angent
        opener.addheaders = [('User-Agent',
                              'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36')]
        # 安装OPener
        request.install_opener(opener)
        try:
            # 使用自己安装好的Opener
            response = request.urlopen('http://www.baidu.com/',timeout=3)
        except :
            return False;

        # 读取相应信息并解码
        html = response.read().decode("utf-8")
        if re.search('百度',html):
            return True;
        else:
            return False;

if __name__ == "__main__":
    print(TestProxy.checkProxy(proxyIp='110.52.235.154:9999'))
    print(TestProxy.checkProxy(proxyIp='112.112.236.145:9999'))
    print(TestProxy.checkProxy(proxyIp='118.193.107.174:80',type='http'))
    print(TestProxy.checkProxy(proxyIp='106.46.136.112:808',type='http'))
    # 'http': ''
    # 'https': "",
    # "http": "http://"